package com.xzlzx.appnium.verticle

import io.appium.java_client.android.AndroidDriver
import io.vertx.core.AbstractVerticle
import io.vertx.core.Vertx
import org.openqa.selenium.remote.DesiredCapabilities

import java.util.concurrent.TimeUnit

class AppniumVerticle extends AbstractVerticle{

    static void main(String[] args) {
        Vertx.vertx().deployVerticle(AppniumVerticle.newInstance())
    }

    @Override
    void start() throws Exception {
        DesiredCapabilities cap = new DesiredCapabilities()
        //appium做自动化
        cap.setCapability("automationName", "Appium")
        //设备名称
        cap.setCapability("deviceName", "m1")
        //安卓自动化还是IOS自动化
        cap.setCapability("platformName", "Android")
        //被测app的包名
        cap.setCapability("appPackage", "com.meizu.flyme.calculator")
        //被测app的入口Activity名称
        cap.setCapability("appActivity", ".Calculator")
        //把以上配置传到appium服务端并连接手机
        AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap)
        //隐式等待
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS)
        vertx.setPeriodic(10000, {
            //定位元素
            driver.findElementById("com.meizu.flyme.calculator:id/digit5").click()
            driver.findElementById("com.meizu.flyme.calculator:id/digit2").click()
            driver.findElementById("com.meizu.flyme.calculator:id/digit0").click()
            driver.findElementById("com.meizu.flyme.calculator:id/digit1").click()
            driver.findElementById("com.meizu.flyme.calculator:id/digit3").click()
            driver.findElementById("com.meizu.flyme.calculator:id/digit1").click()
            driver.findElementById("com.meizu.flyme.calculator:id/digit4").click()
        })

    }
}
